<template>
  <div class="app-container">
    <!-- 顶部Cards栏 -->
    <!-- <TopBar /> -->
    <!-- 使用货位 -->
    <div class="locationUseArea" v-for="(item, index) in FreightData" :key="index">
      <h2 class="locationUseAreaTitle">{{ item.shelfName }}<span style="font-size: 16px">(其中蓝底绿点表明已使用已启用、蓝底红点表明已使用未启用、红底红点表明未启用未使用、红底绿点表明已启用未使用)</span></h2>
      <div class="locationUseContent">
        <div class="contentBox"
             :style="{'background': (itemz.enable_state == '1' && itemz.use_status === '已使用') ? '#93c9f2' :
             (itemz.enable_state == '0' && itemz.use_status === '已使用') ? '#93c9f2' :
             (itemz.enable_state == '0' ? '#FFCCCC' : '#FFCCCC')}"
             v-for="(itemz, indexz) in item.children"
             :key="indexz"
             @click="itemz.use_status === '已使用' && openPopup(itemz)"
             :class="{'disabled': itemz.use_status === '未使用'}">
          <div>{{ itemz.sto_unit_code }}</div>
          <div :class="itemz.enable_state =='1'? 'statusOk' : 'statusNo'"></div>
        </div>
      </div>
    </div>
    <!-- 打开嵌套表单的 Dialog -->
    <el-dialog title="货品详情" :visible.sync="dialogFormVisible" append-to-body top="150px" width="700px">
      <el-table :data="tableData" style="width:100%">
        <el-table-column align="center" prop="spmch" label="药品名称" width="180">
        </el-table-column>
        <el-table-column align="center" prop="pihao" label="批号" width="180">
        </el-table-column>
        <el-table-column align="center" width="180" prop="sto_unit_code" label="货位号">
        </el-table-column>
        <el-table-column align="center" prop="shl" label="药品数量">
        </el-table-column>
      </el-table>
    </el-dialog>
  </div>
</template>

<script>
import TopBar from "./topBar.vue";
import {
  querySkuByUnitCode
} from "@/api/index/yxl";
export default {
  components: {
    TopBar,
  },
  data() {
    return {
      isDisabled: true, // 用于控制禁用状态
      dialogFormVisible: false,
      tableData: [], //货品详情数据
      FreightData: [],
    };
  },
  methods: {
    openPopup(item) {
      this.dialogFormVisible = true
      const form = {
        unitCode:item.sto_unit_code
      };
      querySkuByUnitCode(form).then(response => {
        this.tableData = response.data;
      });
    },
  },
  watch: {
    '$route.query': {
      immediate: true,
      handler(query) {
        if (query.FreightData) {
          this.FreightData = JSON.parse(query.FreightData);
        }
      }
    }
  },
};
</script>

<style scoped lang="scss">
.locationUseArea {
  padding: 0 20px 15px 20px;
  border-radius: 8px;
  margin-bottom: 15px;
  border: 1px solid #e1e1e1;
}
//禁用
.disabled {
  cursor: not-allowed;
  opacity: 0.5;
}
.locationUseContent {
  max-height: 400px;
  overflow-y: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 27px;
}

.locationUseAreaTitle:before {
  content: "";
  background: #0362fa;
  display: inline-block;
  width: 6px;
  height: 20px;
  margin-right: 10px;
}

.empty {
  width: 100%;
  display: flex;
  justify-content: center;
  align-items: center;
  font-size: 16px;
}

.contentBox {
  background-color: #AEDDCE;
  font-size: 16px;
  padding: 5px;
  text-align: center;
  transition: transform 0.3s ease, box-shadow 0.3s ease;
  position: relative;
  height: 70px;
  width: calc(12.5% - 24px);
  border: 1px solid #e1e1e1;
  border-radius: 8px;
  box-shadow: 5px 5px 10px 0px rgba(0, 0, 0, 0.1);
}

.statusOk:before {
  position: absolute;
  content: '';
  width: 10px;
  line-height: 10px;
  height: 10px;
  left: 50%;
  transform: translateX(-50%);
  bottom: 10px;
  border-radius: 50%;
  background-color: #67c23a;
}

.statusNo:before {
  position: absolute;
  content: '';
  width: 10px;
  line-height: 10px;
  height: 10px;
  left: 50%;
  transform: translateX(-50%);
  bottom: 10px;
  border-radius: 50%;
  background-color: #f56c6c;
}

/* 响应式设计 */
@media (max-width: 768px) {
  .contentBox {
    flex: 1 1 calc(50% - 10px);
    /* 在宽度小于768px时，每行显示2个 */
  }
}

@media (max-width: 480px) {
  .contentBox {
    flex: 1 1 calc(100% - 10px);
    /* 在宽度小于480px时，每行显示1个 */
  }

  .empty {
    font-size: 14px;
    /* 调整字体大小 */
  }

  .contentBox {
    font-size: 12px;
    /* 更小的字体 */
  }
}
</style>
